<div ng-controller="ItemCtrl" ng-init="addAction()" class="sui-form form-horizontal">
    <form name="itemForm" novalidate>
        <ul class="sui-breadcrumb">
            <li><a href="#/item/list">{{'Item'| translate}}</a></li>
            <li class="active">{{item.item_id?'edit':'add_new' | translate}}</li>
        </ul>
        <!--  <div class="control-group" ng-show="false">
            <label class="control-label v-top"><b style="color: #f00;">*</b> {{'store'| translate}}：</label>
            <div class="controls">
                <div>
                    <store-list ng-model="item.store_id" dft="1"></store-list>
                </div>
                <div ng-show="!item.store_id" class="sui-msg msg-error msg-clear help-block error">
                    <div class="msg-con">{{'required'| translate}}</div>
                    <s class="msg-icon"></s>
                </div>
            </div>
        </div> -->

        <div ng-if="item">
            <div ng-if="item.p_item_id *1>0" class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'主商品'| translate}}：</label>
                <div class="controls">
                    <div>{{item.p_item_id}}</div>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'Category'| translate}}：</label>
                <div class="controls">
                    <div class="zTreeDemoBackground">
                        <cat-tree ng-model="item.category_id" dft="1" store="item.store_id"></cat-tree>
                    </div>
                    <div ng-show="!item.category_id" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con">{{'required'| translate}}<a href="#/category/add">点这里创建</a></div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b>{{'outer_id'| translate}}：</label>
                <div class="controls">
                    <input ng-model="item.outer_id" name="outer_id" type="text" value="" class="input-xlarge" required>
                    <div ng-show="itemForm.outer_id.$dirty && itemForm.outer_id.$invalid" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con">{{'required'| translate}}</div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top">{{'标签'| translate}}：</label>
                <div class="controls">
                    <chose-item-label ng-model="item.label" itemid="item.item_id"></chose-item-label>
                    <div ng-show="!item.label.length" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con"><a href="#/label/add">点这里创建</a></div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group" ng-show="false">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'type'| translate}}：</label>
                <div class="controls">
                    <type-id ng-model="item.type_id"></type-id>
                    <div ng-show="itemForm.type_id.$error.required" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con">{{'required'| translate}}</div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'上架状态'| translate}}：</label>
                <div class="controls">
                    <on-shelves ng-model="item.on_shelves" dft="1"></on-shelves>
                    <div ng-show="itemForm.on_shelves.$error.required" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con">{{'required'| translate}}</div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'title'| translate}}：</label>
                <div class="controls">
                    <input ng-model="item.title" type="text" name="name" value="" class="input-xlarge" required>
                    <div ng-show="itemForm.name.$error.required" class="sui-msg msg-error msg-clear help-block error">
                        <div class="msg-con">{{'required'| translate}}</div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'副标题'| translate}}：</label>
                <div class="controls">
                    <textarea rows="3" ng-model="item.note" class="input-xlarge"></textarea>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'item_image'| translate}}：</label>
                <div class="controls">
                    <ul class="sui-row-fluid">
                        <li class="span2">
                            <div>
                                <img ng-src="{{item.img}}" style="width:600px;height: 170px">
                            </div>
                            <label>
                                <br /> 链接：
                                <input ng-model="item.img" type="text" name="name" value="" style="width:100px">
                                <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                    dhf-ng-model="item.img" xtype="url" mult="false" title="Upload"
                                    use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF" setback="setback(attach)"></attachment>
                            </label>
                        </li>
                        <li class="span2">
                            <div>
                                <img ng-src="{{item.img1}}" style="width:600px;height: 170px">
                            </div>
                            <label>
                                <br /> 链接：
                                <input ng-model="item.img1" type="text" name="name" value="" style="width:100px">
                                <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                    dhf-ng-model="item.img1" xtype="url" mult="false" title="Upload"
                                    use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF"></attachment>
                            </label>
                        </li>
                        <li class="span2">
                            <div>
                                <div>
                                    <img ng-src="{{item.img2}}" style="width:600px;height: 170px">
                                </div>
                                <label>
                                    <br /> 链接：
                                    <input ng-model="item.img2" type="text" name="name" value="" style="width:100px">
                                    <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                        dhf-ng-model="item.img2" xtype="url" mult="false" title="Upload"
                                        use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF"></attachment>
                                </label>
                            </div>
                        </li>
                        <li class="span2">
                            <div>
                                <div>
                                    <img ng-src="{{item.img3}}" style="width:600px;height: 170px">
                                </div>
                                <label>
                                    <br /> 链接：
                                    <input ng-model="item.img3" type="text" name="name" value="" style="width:100px">
                                    <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                        dhf-ng-model="item.img3" xtype="url" mult="false" title="Upload"
                                        use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF"></attachment>
                                </label>
                            </div>
                        </li>
                        <li class="span2">
                            <div>
                                <div>
                                    <img ng-src="{{item.img4}}" style="width:600px;height: 170px">
                                </div>
                                <label>
                                    <br /> 链接：
                                    <input ng-model="item.img4" type="text" name="name" value="" style="width:100px">
                                    <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                        dhf-ng-model="item.img4" xtype="url" mult="false" title="Upload"
                                        use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF"></attachment>
                                </label>
                            </div>
                        </li>
                    </ul>
                    <div>
                        <input ng-model="item.img" type="hidden" value="" name="img" class="input-xlarge" required>
                    </div>
                    <div ng-show="itemForm.img.$error.required" class="sui-msg msg-error msg-clear help-block error ">
                        <div class="msg-con">{{'required'| translate}}</div>
                        <s class="msg-icon"></s>
                    </div>
                </div>
            </div>
            <div class="control-group" ng-show="false">
                <label class="control-label v-top"> {{'item_in_total_payment'| translate}}：</label>
                <div class="controls">
                    <input ng-model="item.cost" value="" name="cost" class="input-xlarge" required>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'包装费'| translate}}：</label>
                <div class="controls">
                    <input ng-model="item.packing_fee" value="" name="packing_fee">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'是否包邮'| translate}}：</label>
                <div class="controls" ng-show="item.p_item_id *1 ==0">
                    <postage ng-model="item.is_incl_postage" dft="1"></postage>
                    <span ng-if="item.is_incl_postage==2">
                        <postfee-list ng-model="item.fare_id" dft="1"></postfee-list>
                        <div ng-show="!item.fare_id" class="sui-msg msg-error msg-clear help-block error">
                            <div class="msg-con">{{'required'| translate}},没有可以创建新的运费模板<a href="#/postfee/add">创建链接</a>
                            </div>
                            <s class="msg-icon"></s>
                        </div>
                    </span>
                </div>
                <div class="controls" ng-show="item.p_item_id *1>0">
                    <postage ng-model="item.is_incl_postage" stype="1"></postage>
                    <span ng-if="item.is_incl_postage==2">
                        <postfee-list ng-model="item.fare_id" stype="1"></postfee-list>
                    </span>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'发货地址'| translate}}：</label>
                <div class="controls">
                    <chose-pickpoint ng-show="item.p_item_id *1 ==0" member-check="backpickpoint(pickpoint)" title="绑定发货地址" xclass="sui-btn btn-success ng-binding" chosed-items="item.delivery_addrs">
                    </chose-pickpoint>
                    <table class="sui-table table-bordered" style="margin-top:5px " ng-if="item.delivery_addrs">
                        <tbody>
                            <tr ng-repeat="ad in item.delivery_addrs">
                                <td>
                                    <pickpoint-info ng-model="ad"></pickpoint-info>
                                </td>
                                <td>
                                    <button ng-show="item.p_item_id *1 ==0" type="button" class="sui-btn btn-danger" ng-click="item.delivery_addrs.splice($index,1)">{{'delete'|translate}}</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"><b style="color: #f00;">*</b> {{'item_skus'| translate}}：</label>
                <div class="controls">
                    <a ng-show="item.p_item_id *1 ==0" href="javascript:;" ng-show="!item.item_id || uptype" class="sui-btn btn-success btn-small" ng-click="addNewSku(sku);" style="margin-bottom: 10px;">+{{'skus_add'|translate}}</a>
                    <div ng-show="skuNew && item.p_item_id *1 ==0">
                        <div ng-repeat="(skey, sku) in skuNew" style="border:1px solid #EEEEEE;background:#F8F8F8;margin-bottom:10px;padding:10px">
                            规格:
                            <input type="text" name="sku.name" ng-model="sku.name" ng-blur="addNskuName(sku.name,skey)" style="width:100px" required>
                            <button type="button" class="sui-btn btn-danger" ng-click="skuNew.splice($index,1)" ng-show="!item.item_id">{{'delete'|translate}}</button>
                            <div ng-show="sku.name" ng-repeat="(key, value) in sku.values " style="margin: 10px;">
                                <input type="checkbox" name="value.value" ng-checked="isSelected(value.value,sku.name,key)" ng-click="addNewSkuVaue(sku.name,value.value,$event,key,sku.pid)" ng-show="!value.type">
                                <input type="text" name="value.value" ng-show="!value.id" class="picker-text" ng-model="value.value" ng-blur="addNsku(sku.name,value.value,sku.pid,key)" placeholder="增加规格值" maxlength="30">
                                <input type="text" name="value.value" ng-show="value.id" class="picker-text" ng-model="value.value" ng-blur="addNsku(sku.name,value.value,sku.pid,key)" maxlength="30">
                            </div>
                        </div>
                    </div>
                    <!-- sku 重新组合 table 开始 -->
                    <table class="sui-table table-bordered">
                        <tbody>
                            <tr ng-repeat="ab in itemSkuData" ng-show="$index == 0">
                                <!-- <th>ID</th> -->
                                <th style="width:60px;" ng-repeat="cc in ab.data">{{cc.name}}</th>
                                <th style="width:30px">{{'image'| translate}}</th>
                                <th style="width:30px">{{'编码'| translate}}</th>
                                <th style="width:20px">{{'price'| translate}}</th>
                                <th style="width:20px">{{'stocks'| translate}}</th>
                                <th ng-if="(industryCode ==27 || industryCode ==28) && item.p_item_id *1 ==0" style="width:80px;">海关备案商品
                                </th>
                                <!-- <th style="width:20px">{{'条码'| translate}}</th> -->
                                <th style="width:20px">{{'operation'| translate}}</th>
                            </tr>
                            <tr ng-repeat="a in itemSkuData">
                                <!-- <td>{{a|json}}</td> -->
                                <!-- <td>{{a.id}}</td> -->
                                <td ng-repeat="(key, value) in a.data" rowspan="{{value.snum}}" class="{{value.snum?'':'zhide'}}">{{value.value}}</td>
                                <td>
                                    <ul class="unstyled">
                                        <li>
                                            <label><img ng-src="{{newSkus[a.id].imgurl}}" style="width:100px;height: 100px"></label>
                                        </li>
                                        <li>
                                            <label>
                                                <br /> 链接：
                                                <input ng-model="newSkus[a.id].imgurl" type="text" name="name" value=""
                                                    style="width:100px">
                                                <attachment owner-id="item.item_id ?item.item_id:1" owner-type="item"
                                                    dhf-ng-model="newSkus[a.id].imgurl" xtype="url" mult="false"
                                                    title="Upload" use-type="png,jpeg,gif,jpg,JPG,PNG,JPEG,GIF">
                                                </attachment>
                                            </label>
                                        </li>
                                    </ul>
                                </td>
                                <td>
                                    <div>
                                        外部编码:
                                        <input type="text" name="newSkus[a.id].sku_outer_id" ng-model="newSkus[a.id].sku_outer_id" style="width:120px" ng-show="item.p_item_id *1 ==0" required>
                                        <span ng-show="item.p_item_id *1 >0"> {{newSkus[a.id].sku_outer_id}}</span>
                                    </div>
                                    <div style="margin-top: 5px;">
                                        条形码：
                                        <input type="text" ng-show="item.p_item_id *1==0" name="newSkus[a.id].barcode" ng-model="newSkus[a.id].barcode" style="width:120px">
                                        <span ng-show="item.p_item_id *1>0"> {{newSkus[a.id].barcode}}</span>
                                    </div>
                                    <div style="margin-top: 5px;background: #ccc;padding: 5px;" ng-if="item.xtype*1>0">
                                        税率:
                                        <!-- smart-float -->
                                        <input type="text" name="newSkus[a.id].tax_rate" ng-model="newSkus[a.id].tax_rate" style="width:80px" ng-show="item.p_item_id *1==0">
                                        <span ng-show="item.p_item_id *1 >0"> {{newSkus[a.id].tax_rate}}</span>
                                        <div>说明：1、如果不给顾客显示税费，这里填写0即可。如果要显示，请保持税率与右侧备案商品的税率一致。</div>
                                        <div>2、税率格式必须是小数类型，例如：0.091</div>
                                    </div>
                                    <choice-customs-items ng-show="(industryCode ==27 || industryCode ==28) && item.p_item_id *1 ==0" sku-code="newSkus[a.id].sku_outer_id" barcode="newSkus[a.id].barcode" del="item.delivery_addrs">
                                    </choice-customs-items>
                                </td>

                                <td>
                                    <input type="number" name="newSkus[a.id].sku_price" ng-model="newSkus[a.id].sku_price" style="width:50px">
                                    <sku-taxfee ng-if="item.xtype*1>0" outerid="newSkus[a.id].sku_outer_id" price="newSkus[a.id].sku_price"></sku-taxfee>
                                    <span ng-show="item.p_item_id && newSkus[a.id].sku_outer_id">
                                        <main-sku-fee outerid="newSkus[a.id].sku_outer_id" pitemid="item.p_item_id"></main-sku-fee>
                                    </span>
                                </td>
                                <td>
                                    <input ng-show="item.p_item_id *1==0" type="number" name="newSkus[a.id].sku_stocks" ng-model="newSkus[a.id].sku_stocks" style="width:30px">
                                    <span ng-show="item.p_item_id *1>0"> {{newSkus[a.id].sku_stocks}}</span>
                                </td>
                                <!-- <td>
                                    <input type="text" name="newSkus[a.id].barcode" ng-model="newSkus[a.id].barcode" style="width:80px">
                                </td> -->
                                <td ng-if="(industryCode ==27 || industryCode ==28) && item.p_item_id *1 ==0">
                                    <custome-one outerid="newSkus[a.id].sku_outer_id"></custome-one>
                                </td>
                                <td>
                                    <div ng-show="item.p_item_id *1==0">
                                        <button ng-show="newSkus[a.id].sku_id && newSkus[a.id].status_id==1" type="button" class="sui-btn btn-danger" ng-click="itemSkuStatusUpdate(newSkus[a.id],2)">{{'禁用'|translate}}</button>
                                        <button ng-show="newSkus[a.id].sku_id && newSkus[a.id].status_id==2" type="button" class="sui-btn btn-warning" ng-click="itemSkuStatusUpdate(newSkus[a.id],1)">{{'启用'|translate}}</button>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'销量'| translate}}：</label>
                <div class="controls">
                    <input ng-model="item.sale_num" type="number" value="" name="sale_num" class="ng-pristine ng-untouched ng-valid">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'重量'| translate}}：</label>
                <div class="controls">
                    <input ng-if="item.p_item_id *1==0" ng-model="item.weight" type="text" value="" name="weight" class="ng-pristine ng-untouched ng-valid">
                    <span ng-if="item.p_item_id *1>0">{{item.weight}}</span> 千克
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'是否虚拟商品'| translate}}：</label>
                <div class="controls">
                    <isvirtual ng-if="item.p_item_id * 1 == 0" ng-model="item.is_virtual"></isvirtual>
                    <isvirtual ng-if="item.p_item_id * 1 > 0" ng-model="item.is_virtual" stype="1"></isvirtual>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'支付限制'| translate}}：</label>
                <div class="controls">
                    <limit-pay ng-if="item.p_item_id *1==0" ng-model="item.limit_pay" dft="1"></limit-pay>
                    <limit-pay ng-if="item.p_item_id *1>0" ng-model="item.limit_pay" stype="1"></limit-pay>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'顾客付款后可见'| translate}}：</label>
                <div class="controls">
                    <item-vdesc ng-model="item.vdesc" ng-if="item.p_item_id *1==0"></item-vdesc>
                    <div style="width: 300px;" ng-bind-html="item.vdesc | html"></div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'商品类型'| translate}}：</label>
                <div class="controls">
                    <item-type ng-if="item.p_item_id *1==0" ng-model="item.xtype" dft="1"></item-type>
                    <item-type ng-if="item.p_item_id *1>0" ng-model="item.xtype" stype="1"></item-type>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"></label>
                <div class="controls">
                    <button type="submit" id="submit" class="sui-btn btn-primary" ng-disabled="!(itemForm.$valid && itemSkuData && item.category_id ) " ng-click="itemAdd($event)">
                        <span>{{'save' | translate}}</span>
                    </button>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label v-top"> {{'商品描述'| translate}}：</label>
                <div class="controls">
                    <ueditor ng-model="item.description" uid="{{itemdescription}}itemdescription" style="width:694px">
                    </ueditor>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"></label>
                <div class="controls">
                    <button type="submit" id="submit" class="sui-btn btn-primary" ng-disabled="!(itemForm.$valid && itemSkuData && item.category_id ) " ng-click="itemAdd($event)">
                        <span>{{'save' | translate}}</span>
                    </button>
                </div>
            </div>
        </div>
    </form>
</div>